package net.minecraft.src;

import java.util.logging.Logger;

import codechicken.wirelessredstone.core.*;
import net.minecraft.server.MinecraftServer;
import net.minecraft.src.forge.MinecraftForge;

public class mod_WirelessRedstoneCore extends BaseModMp
{
	public void ModsLoaded()
    {
		super.ModsLoaded();
		ModLoader.SetInGameHook(this, true, true);		
		
		Packet.addIdClassMapping(SaveManager.config().getTag("core.packet.id").getIntValue(235), true, true, PacketRedstoneEther.class);
        PacketRedstoneEther.assignHandler(new int[]{1,19}, new CorePacketHandler());
		MinecraftForge.registerSaveHandler(RedstoneEtherSaveHandler.getInstance());
    }
	
	private static void init()
	{
		ConfigTag coreconfig = SaveManager.config().getTag("core").useBraces().setPosition(10);
		ConfigTag itemconfig = coreconfig.getTag("item").useBraces();
		
		RedstoneEther.init();
		
		obsidianStick = new Item(itemconfig.getTag("obsidianStick.id").getIntValue(6150));
		stoneBowl = new Item(itemconfig.getTag("stoneBowl.id").getIntValue(6151));
		retherPearl = new Item(itemconfig.getTag("retherPearl.id").getIntValue(6152));
		wirelessTransceiver = new Item(itemconfig.getTag("wirelessTransceiver.id").getIntValue(6153));
		powerfulTransceiver = new Item(itemconfig.getTag("powerfulTransceiver.id").getIntValue(6154));
		satelliteDish = new Item(itemconfig.getTag("satelliteDish.id").getIntValue(6155));
		netherrackStick = new Item(itemconfig.getTag("netherrackStick.id").getIntValue(6156));
		blazeRod = new Item(113);
		
		addRecipies();
	}	
	
	private static void addRecipies()
	{
		CraftingManager.getInstance().addRecipe(new ItemStack(obsidianStick), new Object[]{
			"O", 
			"O", 
			Character.valueOf('O'), Block.obsidian});
		CraftingManager.getInstance().addRecipe(new ItemStack(stoneBowl), new Object[]{
			"S S", 
			" S ", 
			Character.valueOf('S'), Block.stone});
		CraftingManager.getInstance().addRecipe(new ItemStack(retherPearl), new Object[]{
			"rgr", 
			"gpg", 
			"rgr", 
			Character.valueOf('r'), Item.redstone, 
			Character.valueOf('g'), Item.lightStoneDust, 
			Character.valueOf('p'), Item.enderPearl});
		CraftingManager.getInstance().addRecipe(new ItemStack(retherPearl), new Object[]{
			"grg", 
			"rpr", 
			"grg", 
			Character.valueOf('r'), Item.redstone, 
			Character.valueOf('g'), Item.lightStoneDust, 
			Character.valueOf('p'), Item.enderPearl});
		CraftingManager.getInstance().addRecipe(new ItemStack(wirelessTransceiver), new Object[]{
			"r", 
			"o", 
			Character.valueOf('r'), retherPearl,
			Character.valueOf('o'), obsidianStick});
		CraftingManager.getInstance().addRecipe(new ItemStack(powerfulTransceiver), new Object[]{
			"r", 
			"b", 
			Character.valueOf('r'), retherPearl,
			Character.valueOf('b'), blazeRod});
		CraftingManager.getInstance().addRecipe(new ItemStack(satelliteDish), new Object[]{
			"t", 
			"b", 
			Character.valueOf('t'), wirelessTransceiver,
			Character.valueOf('b'), stoneBowl});
		CraftingManager.getInstance().addRecipe(new ItemStack(netherrackStick), new Object[]{
			"N", 
			"N", 
			Character.valueOf('N'), Block.netherrack});
		CraftingManager.getInstance().addRecipe(new ItemStack(blazeRod), new Object[]{
			"gl", 
			"ng", 
			Character.valueOf('g'), Item.lightStoneDust,
			Character.valueOf('n'), netherrackStick,
			Character.valueOf('l'), Item.bucketLava});
	}

	public String Version()
	{
		return "CBE 1.0.0";
	}
	
	public void OnTickInGame(MinecraftServer mc)
	{
		RedstoneEther.tick(mc.worldMngr[0]);
		RedstoneEther.tick(mc.worldMngr[1]);
		RedstoneEtherGui.update();
	}
	
	public boolean HandleCommand(String s, String s1, Logger logger, boolean flag)
	{
		ICommandListener commandsender;
		if(s1.equals("CONSOLE"))
		{
			commandsender = ModLoader.getMinecraftServerInstance();
		}
		else
		{
			commandsender = ModLoader.getMinecraftServerInstance().configManager.getPlayerEntity(s1).playerNetServerHandler;
		}
		return RedstoneEtherCommandHandler.handleCommand(s, s1, commandsender, flag);
	}
	
	public void HandleLogin(EntityPlayerMP player)
	{
		RedstoneEther.HandleLogin(player);
	}

	public static Item obsidianStick;
	public static Item stoneBowl;
	public static Item retherPearl;
	public static Item wirelessTransceiver;
	public static Item powerfulTransceiver;
	public static Item satelliteDish;
	public static Item netherrackStick;
	public static Item blazeRod;
	
	public static final String texfile = "/codechicken/wirelessredstone/core/wireless1.png";
	

	static
	{
		init();
	}
}
